package scene;

/// A class representing a 4-channel RGBA color. Channel values range from 0.0f to 1.0f.
public class Color {
	// / Create a default color (opaque black).
	public Color() {
		r = g = b = 0.0f;
		a = 1.0f;
	}

	// / Create a fully opaque color.
	public Color(float newR, float newG, float newB) {
		r = newR;
		g = newG;
		b = newB;
		a = 1.0f;
	}

	// / Create a color from red, green, blue, and alpha channels.
	public Color(float newR, float newG, float newB, float newA) {
		r = newR;
		g = newG;
		b = newB;
		a = newA;
	}

	public Color(int[] result) {
		r = (float) result[0] / 255f;
		g = (float) result[1] / 255f;
		b = (float) result[2] / 255f;
	}

	public Color(Color col) {
		r = col.r;
		g = col.g;
		b = col.b;
	}

	public void addLocal(Color c) {
		r += c.r;
		g += c.g;
		b += c.b;
	}

	public void divideLocal(float d) {
		r /= d;
		g /= d;
		b /= d;
	}

	// / Color components. 1.0f == channel at full, 0.0f == channel at 0%.
	public float r;
	public float g;
	public float b;
	public float a;
	private boolean isBackgroundHit = false;

	public int[] asInt() {
		int[] i = new int[3];
		i[0] = Math.min((int) (this.r * 255), 255);
		i[1] = Math.min((int) (this.g * 255), 255);
		i[2] = Math.min((int) (this.b * 255), 255);
		return i;
	}

	public void mulLocal(float f) {
		r *= f;
		g *= f;
		b *= f;
	}

	public Color mul(float f) {
		Color c = new Color(this);
		c.mulLocal(f);
		return c;
	}

	public Color mul(Color o) {
		Color c = new Color(this);
		c.mulLocal(o);
		return c;
	}

	public void mulLocal(Color c) {
		r *= c.r;
		g *= c.g;
		b *= c.b;
	}

	@Override
	public String toString() {
		return "" + r + " " + g + " " + b;
	}

	public boolean isZero() {
		return r == 0 && g == 0 && b == 0;
	}

	public void setBackgroundHit(boolean b) {
		this.isBackgroundHit = b;
	}
	
	public boolean isBackgroundHit() {
		return this.isBackgroundHit;
	}

}
